﻿using System;
using System.Windows.Forms;

namespace Marmat.Forms
{
    public partial class FileManager : Skin.ScrollControl, IBindingField, IControl, IBindingFieldNotification
    {
        public FileManager()
        {

            // 此调用是设计器所必需的。
            this.InitializeComponent();

            // 在 InitializeComponent() 调用之后添加任何初始化。
            this.SetStyle(ControlStyles.Selectable, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true); // 尺寸变化后绘制
            this.SetStyle(ControlStyles.Opaque, false); // 改善绘图质量
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
        }

        /// <summary>
        /// 是否正在更新Value
        /// </summary>
        /// <remarks></remarks>
        protected bool Updating = false;

        /// <summary>
        /// 构建文件id时的规则。
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public virtual string BuildFileID(string fileName)
        {
            var info = new System.IO.FileInfo(fileName);
            string id = Guid.NewGuid().ToString().Replace("-", null).ToLower() + info.Extension;
            if (!string.IsNullOrEmpty(this.RootDir))
            {
                id = System.IO.Path.Combine(this.RootDir, id);
            }

            return id;
        }

        /* TODO ERROR: Skipped RegionDirectiveTrivia */
        public void OnAfterAddFile(FileItemEventArgs e)
        {
            AfterAddFile?.Invoke(this, e);
        }

        public void OnBeforeAddFile(FileItemCancelEventArgs e)
        {
            BeforeAddFile?.Invoke(this, e);
        }

        protected virtual void NotifyPropertyChanged()
        {

        }

        void IBindingFieldNotification.NotifyPropertyChanged()
        {
            this.NotifyPropertyChanged();
        }
    }
}